package br.com.bestOffer.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value="DoubleConverter")
public class DoubleConverter implements Converter{

	    @Override  
	    public Object getAsObject(FacesContext arg0, UIComponent arg, String value) {  
	    		
	          String valor = null;
	          
	    	  if(value != null || value != "") {  
	    		  valor = value.replaceAll("R$", "");
	              valor = valor.toString().replaceAll(".", "");  
	          }  
	    	  
	        if (valor != null) {  
	            if (valor.isEmpty() == false) {  
	            	return new Double(valor); 
	            }  
	        }  
	  
	        return null;
	        
	    }  
	  
	    @Override  
	    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {  
	        return arg2.toString();  
	    }  
}
